let fs = require('fs');
let readStream = require('./myReadStream')

// let rs = fs.createReadStream('./a.txt', {
//     flags: 'r',
//     encoding: null,
//     fd: null,
//     mode: 0o666,
//     autoClose: true,
//     start: 0,
//     end: Infinity,
//     highWaterMark: 4
// });

let rs = new readStream('./a.txt', {
    flags: 'r',
    encoding: null,
    // fd: null,
    mode: 0o666,
    autoClose: true,
    start: 0,
    end: 9,
    highWaterMark: 2
})

let arr = [];

rs.on('open', function(fd) {
    console.log(fd)
})

rs.on('data', function(data) {
    arr.push(data)
})

rs.on('end', function() { 
    console.log(Buffer.concat(arr).toString())
})

rs.on('close', function() {
    console.log('close')
})

rs.on('error', function(err) {
    console.log(err)
})

rs.pause()
setTimeout(() => {
    rs.resume()
}, 2000)